package jfuzzyprincepless.algorithm.structure;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import jfuzzyprincepless.agents.BaseNegotiationAgent;
import jfuzzyprincepless.agents.INegotiatingAgent;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class CompoundConstruction
	extends BaseNegotiationAgent
	implements INegotiationConstruction
{
	private List<INegotiatingAgent> agentsList =
		new ArrayList<INegotiatingAgent>();

	public CompoundConstruction(
		INegotiationConstruction ... constructions
	) {
		this(Arrays.asList(constructions));
	}

	public CompoundConstruction(List<INegotiationConstruction> constructions) {
		for (INegotiationConstruction construction : constructions) {
			agentsList.addAll(construction.getAgentsList());
		}
	}

	@Override
	public List<INegotiatingAgent> getAgentsList() {
		return Collections.unmodifiableList(agentsList);
	}

	@Override
	public boolean negotiate(INegotiationContext context) {
		context.registerService(this);
		return super.negotiate(context);
	}
}
